<?php
require_once APP  . '/application/admincontrollers/AdminAction.php';
/**
 * 所有一层分类管理
 * 
 * @author RD
 * @version 
 */
    
class AlllistController extends AdminAction
{
	/**
	 * Enter description here...
	 *
	 * @var Alllist
	 */
    private $_alllist;
    
    /**
     * initial function
     *
     */
    public function init()
    {
        require_once APP.'/application/models/Alllist.php';
        
        //后台管理员对象
        $this->_alllist = new Alllist($this->db);
    }
    
    /**
     * 管理
     *
     */
    public function manageAction()
    {
    	$type = (int)$this->getParam('type', 0);
    	$list = $this->_alllist->getAllListByType($type);
    	
    	$this->view->list = $list;
    	$this->view->type = $type;
    }
    
    /**
     * 添加界面
     *
     */
    public function addAction()
    {
    	$type = (int) $this->getParam('type', 0);
    	
    	$this->view->type = $type;
    }
    
    public function doaddAction()
    {
    	try{
    		$type = $this->getParam("type");
    		$name = $this->getParam("name");
    		$seq = $this->getParam("seq");
    		$hidden = $this->getParam("hidden");
    		$isleaf = $this->getParam("isleaf");
    		
    		$this->_alllist->add($type, $name, $seq, $hidden, $isleaf);
    	$this->view->msg = '添加成功';
    	}catch (Exception $e){
    		$this->view->msg = '添加失败，' . $e->getMessage();
    	}
    	
    	$this->view->url = $this->url($this->view->baseUrl, "alllist", 'manage', 'type=' . $this->getParam('type', 0), 'admin');
    	
    	$this->showmessage();
    }
    
    /**
     * 编辑界面
     *
     */
    public function editAction()
    {
    	$id = (int) $this->getParam('id', 0);
    	$detail = $this->_alllist->getDetailByID($id);
    		
    	$this->view->detail = $detail;
    }
    
    public function doeditAction()
    {
    	try{
    	$vlaue = array();
    	$vlaue['name'] = $this->getParam("name");
    	$vlaue['seq'] = $this->getParam("seq");
    	$vlaue['hidden'] = $this->getParam("hidden");
    	$vlaue['isleaf'] = $this->getParam("isleaf");
    	
    	$this->_alllist->change((int)$this->getParam("id"), $vlaue);
    	$this->view->msg = '编辑成功';
    	}catch (Exception $e){
    		$this->view->msg = '编辑失败，' . $e->getMessage();
    	}
    	
    	$this->view->url = $this->url($this->view->baseUrl, "alllist", 'manage', 'type=' . $this->getParam('type', 0), 'admin');
    	
    	$this->showmessage();
    }
    
    public function delAction()
    {
    	try{    	
    		$this->_alllist->delete($this->getParam("id"));
    		$this->view->msg = '删除成功';
    	}catch (Exception $e){
    		$this->view->msg = '删除失败，' . $e->getMessage();
    	}
    	
    	$this->view->url = $this->url($this->view->baseUrl, "alllist", 'manage', 'type=' . $this->getParam('type', 0), 'admin');
    	
    	$this->showmessage();
    }
}
